﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace EQual.MainModule.Projects.Views
{
    /// <summary>
    /// Interaction logic for ProjectsGridView.xaml
    /// </summary>
    public partial class ProjectsGridView : UserControl ,IProjectsGridView 
    {
        public ProjectsGridView()
        {
            InitializeComponent();
        }

        #region IListView<object,object> Members

        public object Model
        {
            get
            {
                return this.DataContext;
            }
            set
            {
                this.DataContext = value;

            }
        }

        public event EventHandler<Microsoft.Practices.Composite.Events.DataEventArgs<object>> ItemSelected;

        public event EventHandler<Microsoft.Practices.Composite.Events.DataEventArgs<object>> ItemDeleted;

        public event EventHandler<Microsoft.Practices.Composite.Events.DataEventArgs<object>> ItemAdded;

        #endregion

        private void dataGrid1_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if(ItemSelected != null)
            ItemSelected(this, new Microsoft.Practices.Composite.Events.DataEventArgs<object>(dataGrid1.SelectedItem));
        }

        private void dataGrid1_RowEditEnding(object sender, Microsoft.Windows.Controls.DataGridRowEditEndingEventArgs e)
        {
            if (e.EditAction == Microsoft.Windows.Controls.DataGridEditAction.Commit)
            {
                if(ItemAdded != null )
                ItemAdded(this, new Microsoft.Practices.Composite.Events.DataEventArgs<object>(dataGrid1.SelectedItem));
            }
        }

        #region IProjectsGridView Members

        bool _isEditable ;

        public bool IsEditable
        {
            get { return _isEditable; }
            set
            {
                _isEditable = value;
                this.dataGrid1.CanUserAddRows = value;
                this.dataGrid1.CanUserDeleteRows = value;

            }
        }
 
        #endregion
    }
}
